<template>
  <div>
    	<div class="bg">
    		<img src="../assets/loginbg.png"/>
    	</div>
    	<!--==-->
    	<div class="input">
	      <div class="input_main" @keydown.enter='login'>
	    		<div class="input_input">
	    			<h4 class="input_each">
	    				<span class="iconfont baiColor">&#xe652;</span>
	    				<input type="number" ref="phone"   value="" />
	    			</h4>
	    			<h4 class="input_each">
	    				<span class="iconfont baiColor">&#xe64f;</span>
	    				<input type="password" ref="pw"   value="" />
	    			</h4>
	    		</div>
	    		<router-link to="/wfindpw">
	    		<div class="findpw clearfix">
	    			<p class="pull-right">忘记密码</p>
	    		</div>
	    		</router-link>
	    		<div class="input_button button _width baiColor" @click="login">
	    			<p>登录</p>
	    		</div>
	    		<router-link to="/wreg">
		    		<div class="input_button button _width baiColor">
		    			<p>注册</p>
		    		</div>
	    		</router-link>
	    	</div>
    	</div>
  </div>
</template>

<script>
export default {
  mounted(){
  	var info = window.localStorage.data;
  	if(info != undefined){
  		this.$refs.phone.focus();
  		this.$router.push("iIndex");
  	}
			
	},
  methods:{
  	//登录
  	login(){
  		var _this = this;
  		var phone = this.$refs.phone.value;	//手机号
  		var pw = this.$refs.pw.value;	//密码
		if(phone == "" || pw == ""){
			alert("请完善您的信息");
		}else{
			var params = new URLSearchParams();
			params.append('phone', phone);
			params.append('pwd', pw);
			this.$axios({
			   url:"One/Login/index",
					method:"post",
					data:params
				}).then(function(res){
						if(res.data.status == 1){
							localStorage.data = res.data.data;	//秘钥
							_this.$router.push("iIndex")	//首页
							_this.$refs.phone.value = "";
							_this.$refs.pw.value = "";
						}else{ 
							alert("账号或密码错误，请重新输入")
							_this.$refs.pw.value = "";
						}
				}).catch(function(err){
					console.log(err)		
				})
		}
  	},
  	
  }
}
</script>

<style scoped>
	@import "../css/public.css";
	@import "../css/login.css";
</style>
